<?php
/**
 * 底层权限、用户操作类
 * 
 */

if(!defined('IN_SERVER')) 
{
	exit('invalid request');
}

class MemberHandler 
{	
	var $MemberAcount ='';
	var $MemberPassword = '';
	var $MemberToken ='';
	var $MemberFields = array();
	var $ActionList = array();
	var $CurrentAction = array();	
	var $_Error = array();

	function MemberHandler() 
	{

	}
	
	function init() 
	{
		$pass = '';
		$acount = '';
		return $this->FetchMember($acount, $pass);
	}
	
	function FetchMember($acount, $token) 
	{
		$this->MemberAcount  = trim($acount);
		$this->MemberToken = trim($token); //去除两端空格
		$this->GetMember();
		if(!empty($this->MemberFields))
		{
			jdefine("PLAYER_ACCOUNT", 	$this->MemberFields['player_account']);
			jdefine("PLAYER_TOKEN", 	$this->MemberFields['player_token']);
			jdefine("PLAYER_PASSWORD",  $this->MemberFields['player_password']);
			jdefine("PLAYER_NAME", 		$this->MemberFields['player_name']);
			jdefine("PLAYER_LEVEL", 	(int)$this->MemberFields['player_level']);
			jdefine("PLAYER_MONEY",  	(int)$this->MemberFields['player_money']);
			jdefine("PLAYER_GOLD",   	(int)$this->MemberFields['player_gold']);
			jdefine("PLAYER_SEX",   	$this->MemberFields['player_sex']);
			jdefine("PLAYER_ICON",   	$this->MemberFields['player_icon']);
			jdefine("PLAYER_LOGIN_TIME",   $this->MemberFields['player_login_time']);
		}
		
		return $this->MemberFields;
	}

	function UpdateSessions() 
	{
		
	}

	function access($mod, $code = '', $uid = 0, $is_admin = 0) 
	{
		return $this->HasPermission($mod, $code, $is_admin, $uid);
	}
	
	function HasPermission($mod, $code, $is_admin=0, $uid=0) 
	{
		$MemberFields = array();
		return true;
	}
	
	function GetMemberFields() 
	{
		return $this->MemberFields;
	}
	
	function GetMember() 
	{
		global $_J;
		$this->MemberFields = array();
		
		$sql = '';
		if($this->MemberAcount !='' && $this->MemberToken !='')
		{
			$sql ="SELECT * FROM ".DB::table("bd_player")." WHERE player_account='{$this->MemberAcount}' AND player_token='{$this->MemberToken}'";
		}
		if($sql)
		{
			$this->MemberFields = DB::fetch_first($sql);
		}
		if(empty($this->MemberFields))
		{
			$sql ="SELECT * FROM ".DB::table("bd_player")." WHERE player_account='{$this->MemberAcount}'";
			$sql_result = DB::fetch_first($sql);
			if(empty($sql_result))
			{
				$_J['mc'] =1;
				$_J['warring_msg_id'] ="warring_id001";
			}
			else 
			{
				$_J['mc'] =1;
				$_J['warring_msg_id'] ="warring_id002";
			}
			
			return false;
		}
		
		$_J['player_account'] = $this->MemberFields['player_account'];
		$_J['player_token'] = $this->MemberFields['player_token'];
		$_J['player_name'] = $this->MemberFields['player_name'];
		$_J['player_level'] = $this->MemberFields['player_level'];
		$_J['player_money'] = $this->MemberFields['player_money'];
		$_J['player_gold'] = $this->MemberFields['player_gold'];
		$_J['player_sex'] = $this->MemberFields['player_sex'];
		$_J['member'] = & $this->MemberFields;
		$_J['mc'] =0;
		$_J['warring_msg_id'] ='';
		
		return true;
	}
	
	function _SetError($error)
	{
		$this->_Error[]=$error;
	}
	
	function GetError()
	{
		return $this->_Error;
	}
}
?>